home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
AOL File Library: 2,801 to 2,900
/
aol-file-protocol-4400-2801-to-2900.zip
/
AOLDLs
/
C++ Files Library
/
FFT and Complex Numbers Library
/
FFTLibrary.sit
/
FFT library ƒ
/
IFFT.cp
< prev
next >
Wrap
Text File
|
1995-01-15
|
3KB
|
96 lines
//
// File: IFFT.cp
// Copyright ⌐1994-1995 James Wilson
// All rights reserved.
//
// Revisions:
// 01-15-95: Removed the line that zeros the imaginary during the
// inverse transformation. This only slows the code, and does not
// take in the possibility of complex data. If the data is real,
// code that uses this library should ignore the imaginary results
// of the IFFT.
// 08-02-94: Took out the constant multiplication part of arg and
// placed into halfArg. halfArg is multiplied by p to get arg.
// Removed the "f" suffix from 1.0 on line 34. Removed the "f"
// suffix from 0.0 on line 86. Replaced the name "temp" by "swap."
// 07-29-94: Replaced all instances of floating-point division with
// multiplication by reciprocals, since multiplication is much
// faster on PowerPC.
//
// This is the implementation file for the Inverse Fourier transform (IFFT)
// algorithm. The algorithm is the same as the FFT, except for the sign
// of the comlex exponential and the final multiplication by 1/n. I assume
// that the reader or user of this code has a decent understanding of both
// the DFT, FFT, and inverse transforms.
#ifndef __FFT__
#include "FFT.h"
#endif
void IFFT(const long n, const long nu, ComplexArray functionOut)
{
long n2, nu1, i, k, p, x, tempIndex, denom;
double arg, reciprocalN, halfArg;
Complex exponent, swap;
// Initalization process.
x = 1L;
n2 = n / 2L;
nu1 = nu - 1L;
k = 0L;
reciprocalN = 1.0 / n;
halfArg = twoPi * reciprocalN;
// First step: calculate the Fourier transforms of the ComplexArray values.
// The results are scrambled and are unscrambled at the end (see
// below).
while(x <= nu)
{
for(i = 1L; i <= n2; i++, k++)
{
denom = LongPower(2L, nu1);
p = BitReverse(k/denom, nu);
arg = halfArg * p;
exponent.Real() = cos(arg);
exponent.Imag() = sin(arg);
tempIndex = k + n2;
swap = exponent * functionOut[tempIndex];
functionOut[tempIndex] = functionOut[k] - swap;
functionOut[k] += swap;
}
k += n2;
if(k >= n)
{
x++;
n2 /= 2L;
nu1--;
k = 0L;
}
}
// Last step: unscramble the results. This is done by swapping the
// values in functionOut[k] with functionOut[BitReverse(k, nu)].
// Then multiply each element by 1/n. The imaginary part will be close
// to zero, but due to precision problems, it will not be equal to 0.0.
while(k < n)
{
i = BitReverse(k, nu);
if(i > k)
{
swap = functionOut[k];
functionOut[k] = functionOut[i];
functionOut[i] = swap;
}
functionOut[k].Real() *= reciprocalN;
k++;
}
}